//
//  TableViewControllerImpl.swift
//  letu
//
//  Created by gaoguangxiao on 2022/3/23.
//

import Foundation
import UIKit
import SnapKit

class TableViewControllerImpl: ViewControllerImpl {
    
    var tableView: UITableView?
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override convenience init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        
        self.init(style: .plain)
    }
    
    init(style:UITableView.Style){
        
        super.init(nibName: nil, bundle: nil)
        
        let tbl = UITableView(frame: .zero, style: style)
        tbl.dataSource = self
        tbl.delegate   = self
        tbl.separatorStyle = .singleLine
        tbl.rowHeight = 52
        tbl.contentInset = UIEdgeInsets(top: 5, left: 0, bottom: 0, right: 0)
        if #available(iOS 15.0, *) {
            tbl.sectionHeaderTopPadding = 0
        }
        tableView = tbl
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        if let tbl = tableView {
            self.view.addSubview(tbl)
            tbl.snp.makeConstraints { make in
                make.top.equalTo(TopBarHeight)
                make.left.bottom.right.equalTo(0)
            }
            if #available(iOS 11.0, *) {
                tbl.contentInsetAdjustmentBehavior = .never
            } else {
                automaticallyAdjustsScrollViewInsets = false
            }
        }
    }
}

extension TableViewControllerImpl : UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return UITableViewCell()
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
}
